using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using MemberMgr.Data.ManagerObjects;
using MemberMgr.Data.BusinessObjects;
using MemberMgr.Data.Base;

namespace MemberMgr.Data.UnitTests
{
	[TestFixture]
    public partial class tSystemTests : UNuitTestBase
    {
        protected ItSystemManager manager;
		
		public tSystemTests()
        {
            manager = managerFactory.GettSystemManager();
        }
		
		protected tSystem CreateNewtSystem()
		{
			tSystem entity = new tSystem();
			
			
			entity.Datakbn = "Test Test Test Test Test Test Test Test Test Test";
			entity.Datakey = "Test Test Test Test Test ";
			entity.Data1 = "Test Test ";
			entity.Data2 = 7;
			entity.Data3 = DateTime.Now;
			entity.Data4 = default(SByte);
			entity.Data5 = "Test Test ";
			entity.Data6 = "Test Test ";
			entity.Data7 = "Test Test ";
			entity.Data8 = "Test Test ";
			entity.Data9 = "Test Test ";
			entity.Data10 = "Test Test ";
			
			return entity;
		}
		protected tSystem GetFirsttSystem()
        {
            IList<tSystem> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				tSystem entity = CreateNewtSystem();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                tSystem entityA = CreateNewtSystem();
				manager.Save(entityA);

                tSystem entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                tSystem entityA = GetFirsttSystem();
				
				entityA.Data1 = "Test Test ";
				
				manager.Update(entityA);

                tSystem entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Datakbn, entityB.Datakbn);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                tSystem entity = GetFirsttSystem();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

